<html>

	<head>
		<meta charset="UTF-8">
		<title>新增角色</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<style>
			.layui-form {
				width: 35%;
			}
			
			.layui-input {
				width: 100% !important;
			}
		</style>
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">

				<!--标题栏-->
				<p class="content_title">角色管理 &nbsp;&nbsp;>&nbsp;&nbsp;修改角色</p>
				<!--标题栏-->

				<form class="layui-form mt20">
					<div class="layui-form-item">
						<label class="layui-form-label">用户名</label>
						<div class="layui-input-block">
							<input type="hidden" name="id" id="id">
							<input type="text" name="userAccount" id="userAccount" lay-verify="required" autocomplete="off" placeholder="请输入用户名" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">组织名称</label>
						<div class="layui-input-block">
							<input type="text" name="userCompanyAllTitle" id="userCompanyAllTitle" lay-verify="required" autocomplete="off" placeholder="请输入组织名称" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">密码</label>
						<div class="layui-input-block">
							<input type="password" name="userPwd" id="userPwd" lay-verify="required" autocomplete="off" placeholder="请输入密码" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">联系人</label>
						<div class="layui-input-block">
							<input type="text" name="linkmanName" id="linkmanName" lay-verify="required" autocomplete="off" placeholder="请输入联系人" class="layui-input w30">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">手机号</label>
						<div class="layui-input-block">
							<input type="text" name="linkmanPhone" id="linkmanPhone" lay-verify="required|phone" autocomplete="off" placeholder="请输入手机号" class="layui-input w30">
						</div>
					</div>
					<!--<div class="layui-form-item">
						<label class="layui-form-label">关联门站</label>
						<div class="layui-input-block">
							<input type="text" name="siteids" id="siteids" lay-verify="required" autocomplete="off" placeholder="请输入关联门站" class="layui-input w30">
						</div>
					</div>-->
					<div class="layui-form-item">
						<label class="layui-form-label">关联门站</label>
						<div class="layui-input-block">
							<select name="siteids" lay-verify="required" lay-search="" id="siteName">
								<option value="">请选择门站</option>
							</select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">状态</label>
						<div class="layui-input-block">
							<input type="radio" name="userStatus" value="0" title="正常" checked="">
							<input type="radio" name="userStatus" value="1" title="禁用">
						</div>
					</div>

					<div class="layui-form-item">
						<div class="layui-input-block">
							<div class="layui-btn" lay-submit="" lay-filter="submitFilter">立即提交</div>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script>
			var href = window.location.href;
			var id = href.split("?")[1].split("&")[2].split("=")[1];

			layui.use(['form', 'layedit', 'upload'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					upload = layui.upload;
					ajaxGet({
					url: 'site/getListNoPage',
					successFull: function(res) {
						if(res.list.length != 0) {
							$.each(res.list, function(i, item) {
								console.log(i)
								$("#siteName").append('<option value="' + item.id + '">' + item.siteName + '</option>');
							});
							layui.form.render('select'); //重新渲染select
						}
					},
					errCallBack: function(res) {}
				});
				//初始化页面值
				$.ajax({
					url: baseUrl + "/user/getById?id=" + id,
					type: "GET",
					dataType: "json",
					success: function(data) {
						$("#id").val(data.id); //id
						$("#userAccount").val(data.userAccount); //用户名
						$("#userCompanyAllTitle").val(data.userCompanyAllTitle); //组织名称
						$("#userPwd").val('......'); //密码
						$("#userPwd").attr('pass',data.userPwd);
						$("#linkmanName").val(data.linkmanName); //联系人
						$("#linkmanPhone").val(data.linkmanPhone); //手机号
						$("#siteName").val(data.siteids); //关联门站
						$("input[name=userStatus][value=0]").attr("checked", data.userStatus == 0 ? true : false); //状态
						$("input[name=userStatus][value=1]").attr("checked", data.userStatus == 1 ? true : false); //状态
						layui.form.render(); //更新全部     
					}
				});
//				$("#userPwd").on("blur",function(){
//					$("#userPwd").attr('pass',$("#userPwd").val())
//				});
				//监听提交
				form.on('submit(submitFilter)', function(data) {
					if($("#userPwd").val() != '......'){
						$("#userPwd").attr('pass',$("#userPwd").val());
					}else{
						$("#userPwd").attr('pass',null);
					};
					ajaxPost({
						url: '/user/update',
						data: {
							id: data.field.id, //id
							userType: 2, //用户类型 0admin甲方 1燃气公司账号 2下游账号 3普通用户
							userAccount: data.field.userAccount, //用户名
							userCompany: data.field.userCompanyAllTitle, //所属公司简称
							userCompanyAllTitle: data.field.userCompanyAllTitle, //所属公司全称
							userPwd: $("#userPwd").attr('pass'), //密码
							linkmanName: data.field.linkmanName, //联系人
							linkmanPhone: data.field.linkmanPhone, //手机号
							siteids: data.field.siteids, //关联门站
							userStatus: data.field.userStatus, //状态
						},
						successFull: function(res) {
							console.log(res)
							layer.msg('修改成功', {
								icon: 6
							});
							window.location.href = "./downstreamList.html?pos=5&childPos=1";
						},
						errCallBack: function(res) {
							layer.msg(res.msg, {
								icon: 6
							});
						}
					})
				});

			});
		</script>
	</body>

</html>